<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<%@ include file="/common/plateform/include/common-base.jsp" %>
	<title>日志配置</title>
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

	<!-- top start -->
	<%@include file="/common/plateform/top.jsp" %>
	<!-- top end -->

	<!-- left start -->
	<%@include file="/common/plateform/left-project.jsp" %>
	<!-- left end-->

	<!-- Main start -->
	<div class="content-wrapper">
		<!-- Main start -->
		<section class="content">
			<div class="row">
				<div class="col-xs-12 ibox">

					<!--搜索  start -->
					<div class="box box-info">

						<!--搜索title  start -->
						<div class="box-header with-border">
							<h3 class="box-title"><i class="fa fa-search"></i> 查询搜索</h3>
							<div class="box-tools pull-right">
								<button type="button" class="btn btn-box-tool"
										data-widget="collapse"><i class="fa fa-minus"></i></button>
								<%--<button type="button" class="btn btn-box-tool" data-widget="remove">
									<i class="fa fa-times"></i></button>--%>
							</div>
						</div>
						<!--搜索title  end -->
						<div class="box-body">
							<form id="searchForm" class="form-horizontal">
								<input type="hidden" name="pageName" value="objName-table"/>
								<input type="hidden" name="formName" value="searchForm"/>
								<input type="hidden" name="orderBy" value="table_prefix"/>
								<input type="hidden" name="sortInfo.w_sortStatus" value="1"/>
								<input type="hidden" name="sortInfo.w_sysName" value=""/>
								<div class="form-group">
									<div class="col-sm-2 text-right"><label class="control-label">表名：</label>
									</div>
									<div class="col-sm-4">
										<input type="text" class="form-control clean"
											   name="sortInfo.wl_infoTableName" value=""/>
									</div>
									<div class="col-sm-2 text-right"><label class="control-label">对象：</label>
									</div>
									<div class="col-sm-4">
										<input type="text" class="form-control clean"
											   name="sortInfo.wl_objName" value=""/>
									</div>
								</div>

								<center>
									<div class="box-footer clearfix">
										<button type="button" class="btn btn-success"
												onclick="getTableData();"><i
												class="fa fa-search"></i> 查询
										</button>&nbsp;
										<button type="button" class="btn btn-warning"
												onclick="mytools.cleanData('#searchForm');">重置
										</button>&nbsp;
									</div>
								</center>
							</form>

						</div>
					</div>
					<!-- 搜索 end -->

					<div class="box box-success">
						<!--列表title  start -->
						<div class="box-header with-border">
							<h3 class="box-title"><i class="fa fa-table"></i> 日志配置 [<span id="span-sysname-text"></span>] [共计<span
									id="dataListTotalCount">0</span>条数据]
							</h3>
							<div class="box-tools pull-right">
								　　　　　　　　
								<button type="button" class="btn btn-box-tool"
										data-widget="collapse"><i class="fa fa-minus"></i>
								</button>
								<%--<button type="button" class="btn btn-box-tool" data-widget="remove">
									<i class="fa fa-times"></i></button>--%>
							</div>
						</div>

						<!-- /.box-header -->
						<div class="box-body">
							<table id="dataList" class="table table-bordered table-hover">
								<thead class="bg-success">
								<tr>
									<th>序号</th>
									<th>表中文名</th>
									<th>表英文名</th>
									<th>对象别名</th>
									<th class="hidden">所属系统</th>
									<th>是否启用日志</th>
									<th >操作</th>
								</tr>
								</thead>
								<tbody id="dataList-body">
								</tbody>
							</table>
							<center>
								<ul id="dataList-page"></ul>
							</center>
						</div>

					</div>
				</div>
			</div>
		</section>
		<!-- Main end -->








		<script type="text/template" id="dataList-template">
			<? for ( var i = 0; i < rows.length; i++) {?>
			<tr>
				<th style="display:none;"  class="<?=rows[i].sortInfo.objName?>_modelId"></th>
				<th style="display:none;"  class="<?=rows[i].sortInfo.objName?>_sortId"><?=strUtil.doNull(rows[i].sortInfo.sortId,'')?></th>
				<td><?=(pageObj.currentPage-1)*10+(i+1)?></td>
				<td><?=strUtil.doNull(rows[i].sortInfo.sortName,'')?></td>
				<td><?=strUtil.doNull(rows[i].sortInfo.infoTableName,'')?></td>
				<td ><?=strUtil.doNull(rows[i].sortInfo.objName,'')?></td>
				<td class="<?=rows[i].sortInfo.objName?>_status">
					已停用
				</td>
				<td>
					<button type="button" class="btn btn-danger btn-xs  hidden <?=rows[i].sortInfo.objName?>-stop" style="margin-right: 8px"
							onclick="toDele('<?=rows[i].sortInfo.objName?>')">
						停用日志
					</button>
					<button type="button" class="btn btn-success btn-xs hidden <?=rows[i].sortInfo.objName?>-stop"
							onclick="toCreate('<?=rows[i].sortInfo.objName?>')">
						字段设置
					</button>
					<button type="button" class="btn btn-success btn-xs <?=rows[i].sortInfo.objName?>-start"
							onclick="start('<?=rows[i].sortInfo.sysName?>','<?=rows[i].sortInfo.sortName?>','<?=rows[i].sortInfo.objName?>')">
						启用日志
					</button>
				</td>
			</tr>
			<?}?>
		</script>

		<script>
            var clickMenu = "log-model-list";
            var  myPage, dataListId, searchFormId;
            myPage = 10;
            dataListId = "dataList";
            searchFormId = "searchForm";
            var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
//            $("#searchForm_sysName").attr("data-condition","uctSys.w_sysEname="+defSysEname);
            $("#span-sysname-text").text(defSysEname+"-"+strUtil.getLocalStorage("sysCname"));
            /**
             * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
             */
            var dictListMap = DictUtil.initDictAndDymic();
            $(function () {
                $("#"+searchFormId).find("input[name='sortInfo.w_sysName']").val(defSysEname);
                //1、加载分页列表数据
                    getTableData();

                //2、控制是否启用token
                //setToken();
            });
            function toDele(objName) {

                var modelId ='';
                modelId = $("."+objName+"_modelId").text();
                if(modelId=='' || modelId==null){
					layer.alert("日志监控表modelId不能为空！");
                    return;
				}
				var flag = toChackModelDetail(modelId);
				if(flag){
                    layer.alert("存在监控字段，不能停用！");
                    return;
				}
                var index_submit = layer.confirm("确认停用日志监控功能吗？", {
                        btn: ['Yes', 'No'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                        var index_load = layer.load(1, {shade: false});
                        $.ajax({
							// type: "post",
							type: "get",
							url: common_info_url,
                            data: {'modelId': modelId, exeType: 'delModel', doCode: 'logExecute'},
                            dataType: 'json',
                            success: function (myData) {

                                if (myData.flag == 'T') {
                                    // layer.msg("停用成功")
                                    layer.alert('日志监控停用成功');
                                    refresh();
                                } else {
                                    layer.alert('日志监控停用失败');
                                }
                                layer.close(index_load);
                            }
                        });
                    })
            }
            //校验是否还有子数据
            function toChackModelDetail(modelId){
                var index_load = layer.load(1, {shade: false});
                var flag = false;
				var paramData={};
				paramData["doCode"] ="logExecute";
				paramData["exeType"] ="modelDetailList";
				paramData["modelId"] =modelId;
                $.ajax({
                    type: 'get',
                    url: common_info_url,
                    data: paramData,
                    dataType: 'json',
                    async: false,
                    success: function (myData) {
                        // console.log(myData);
                        if(myData.total>0){
                            flag = true;
						}
                    }
                });
                layer.close(index_load);
                return flag;
            }
            //反显数据
            function toCreate(objName) {
                var sortId = $("."+objName+"_sortId").text();
                var modelId = $("."+objName+"_modelId").text();
                if (modelId && sortId) {
                    var url = "${page_admin}/project/log-model-detail-list?objName=" + objName + "&sortId=" + sortId+"&modelId="+modelId;
                    mytools.pjax(url);
                }
            }
            //加载列表数据
            function getTableData() {
                var index_load = layer.load(1, {shade: false});
                    $.ajax({
                        type: 'get',
                        url: common_list_url,
                        data: $("#" + searchFormId).serialize() + getCurrentPage(common_list_url + "?" + $("#" + searchFormId).serialize(), myPage),
                        dataType: 'json',
                        async: false,
                        success: function (myData) {
                             console.log("tables",myData);
                            $("#dataListTotalCount").text(myData.total);
                            var data = baidu.template(dataListId + "-template", eval(myData));
                            $("#" + dataListId + "-body").html(data);
                            var option = {
                                ele: $("#" + dataListId + "-page")[0],
                                total: myData.total,
                                fn: getTableData,
                                url: common_list_url + "?" + $("#" + searchFormId).serialize()
                            }
                            generatePages(option);

                        }

                    });
                    $.ajax({
                        type: 'get',
                        <%--url: "${ctx}/trans/list/logModelList",--%>
                        <%--data: {"doCode":"logModelList"},--%>
						url:common_list_url,
						data:{"pageName":"log-model-list","formName":"searchForm","uctLogModel.w_modelSysname":defSysEname},
                        dataType: 'json',
                        async: false,
                        success: function (myData) {
                            for(var i=0; i<myData.rows.length;i++){
                                var modelEname= myData.rows[i].uctLogModel.modelEname;
                                var modelId= myData.rows[i].uctLogModel.modelId;
                                $("."+modelEname+"_status").html("启用中");
                                $("."+modelEname+"-stop").removeClass("hidden");
                                $("."+modelEname+"-start").attr("style","display:none;");
                                $("."+modelEname+"_modelId").html(modelId);
                            }
                        }
                    })
                layer.close(index_load);
            }
            //清空数据
            function cleanData(id) {
                $('#' + id).find(".clean").val("");//按照样式清空；
            }
            function start(sysName, tableName, objName) {
                var url = "${ctx}/trans/submit/";
                var cmsg = "您确定要启用表[" + tableName + "]的日志监控吗？";
                var index_submit = layer.confirm(cmsg, {
                        btn: ['Yes', 'No'],
                        closeBtn: 0,
                        offset: '220px'
                    }
                    , function () {
                    	var paramData={};
                    	paramData["doCode"]="logExecute";
                    	paramData["exeType"]="saveModel";
                    	paramData["modelId"]="";
                    	paramData["modelCname"]=tableName;
                    	paramData["modelEname"]=objName;
                    	paramData["modelBussiness"]=tableName;
                    	paramData["modelSysname"]=sysName;
                    	paramData["modelRemark"]=tableName;
                        layer.close(index_submit);
                        var index_load = layer.load(1, {shade: false});
                        $.ajax({
                            // type: "post",
							type: "get",
                            url: common_info_url,
                            data: paramData,
                            dataType: "json",
                            success: function (myData) {
                                // console.log(myData);
                                if (myData.flag == "T") {
                                    layer.alert("日志监控启用成功");

                                } else {
                                    layer.alert(myData.msg);
                                }
                                refresh();
                                layer.close(index_submit);
                            }
                        });
                    });
            }
            function refresh() {
                getTableData();
            }
            function setToken() {
                $.ajax({
                    type: 'get',
                    url: '${ctx}/sendPage/token?token=true',
                    dataType: 'text',
                    success: function (myData) {
                        console.log(myData);
                        $('#formToken').val(myData);
                    }
                });
            }
            //自定义方法
            //1.定义校验规则-定义
            function setValidate(id) {
                $(id).bootstrapValidator({
                    feedbackIcons: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    }, /** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
                    fields: {
                        "tablePrefix": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                },
                                regexp: {
                                    regexp: /^[a-z]+$/,
                                    message: '只能是小写英文字母！'
                                }
                            }
                        },
                        "sortCode": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                },
                                regexp: {
                                    regexp: /^[a-z_ ]+$/,
                                    message: '只能是小写英文字母，多个单词使用下划线间隔！'
                                }
                            }
                        },
                        "sortName": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                },
                                /* regexp: {
                                     regexp:/^[\u4e00-\u9fa5]*$/,
                                     message: '请输入数据表的中文名！'
                                 }*/
                            }
                        },
                        "objName": {
                            validators: {
                                notEmpty: {
                                    message: '自定义属性不能为空！'
                                },
                                regexp: {
                                    regexp: /^[a-zA-Z]+$/,
                                    message: '请填写英文数据表名-驼峰式！'
                                }
                            }
                        },
                    }
                });
            }

		</script>

	</div>
	<!-- /.content-wrapper -->
	<!-- foot start -->
	<%@include file="/common/plateform/foot.jsp" %>
	<!-- foot start -->
</div>


</body>


</html>

